<?php
    global $_W,$_GPC;
    load() -> func('tpl');
    $ops = array('display', 'edit'); // 只支持此 2 种操作.
    $op = in_array($_GPC['op'], $ops) ? $_GPC['op'] : 'display';
    if($op == 'display'){
        $store = pdo_fetch("select * from".tablename('ew_delivery_store'));
        include $this->template('store_display');
    }
    //仓储编辑
    if ($op == 'edit') {
        $id = intval($_GPC['id']);
        $store = pdo_fetch("select * from".tablename('ew_delivery_store'));
        if (checksubmit()) {
            $data['content'] = $_GPC['content'];
            if(empty($id)){
                $data['createdAt'] = TIMESTAMP;
                $data['updatedAt'] = TIMESTAMP;
                $ret = pdo_insert('ew_delivery_store', $data);
            } else {
                $data['updatedAt'] = TIMESTAMP;
                $ret = pdo_update('ew_delivery_store', $data, array('id'=>$id));
            }

            message('仓储服务保存成功', $this->createWebUrl('store'), 'success');
        }

        include $this->template('store_edit');
    }
?>